﻿Namespace Facades

    Public NotInheritable Class LabelFacade

        Private brother As Infragistics.Windows.Chart.Label

        Public Sub New(ByVal brother As Infragistics.Windows.Chart.Label)
            MyBase.New()
            Me.brother = brother
        End Sub

        <EditableProperty()> _
        Public Property FontSize() As Double
            Get
                Return Me.brother.FontSize
            End Get
            Set(ByVal value As Double)
                Me.brother.FontSize = value
            End Set
        End Property

        <EditableProperty()> _
        Public Property Angle() As Double
            Get
                Return Me.brother.Angle
            End Get
            Set(ByVal value As Double)
                Me.brother.Angle = value
            End Set
        End Property

        <EditableProperty()> _
        Public Property Foreground() As System.Windows.Media.Brush
            Get
                Return Me.brother.Foreground
            End Get
            Set(ByVal value As System.Windows.Media.Brush)
                Me.brother.Foreground = value
            End Set
        End Property

        <EditableProperty()> _
        Public Property Format() As String
            Get
                Return Me.brother.Format
            End Get
            Set(ByVal value As String)
                Me.brother.Format = value
            End Set
        End Property

        <EditableProperty()> _
        Public Property AutoResize() As Boolean
            Get
                Return Me.brother.AutoResize
            End Get
            Set(ByVal value As Boolean)
                Me.brother.AutoResize = value
            End Set
        End Property
        <EditableProperty()> _
        Public Property DistanceFromAxis() As Double
            Get
                Return Me.brother.DistanceFromAxis
            End Get
            Set(ByVal value As Double)
                Me.brother.DistanceFromAxis = value
            End Set
        End Property

        <EditableProperty()> _
        Public Property Visible() As Boolean
            Get
                Return Me.brother.Visible
            End Get
            Set(ByVal value As Boolean)
                Me.brother.Visible = value
            End Set
        End Property

        Public Property FontFamily() As String
            Get
                Return Me.brother.FontFamily.Source
            End Get
            Set(ByVal value As String)
                Me.brother.FontFamily = New Windows.Media.FontFamily(value)
            End Set
        End Property

        <EditableProperty()> _
        Public Property Italic() As Boolean
            Get
                Return Me.brother.FontStyle = Windows.FontStyles.Italic
            End Get
            Set(ByVal value As Boolean)
                Me.brother.FontStyle = If(value, Windows.FontStyles.Italic, Windows.FontStyles.Normal)
            End Set
        End Property

        <EditableProperty()> _
        Public Property Bold() As Boolean
            Get
                Return Me.brother.FontWeight = Windows.FontWeights.Bold
            End Get
            Set(ByVal value As Boolean)
                Me.brother.FontWeight = If(value, Windows.FontWeights.Bold, Windows.FontWeights.Normal)
            End Set
        End Property

        Public Function InternalToXElement() As XElement
            Dim x = <Label
                        Angle=<%= Angle %>
                        FontSize=<%= FontSize %>
                        Foreground=<%= Foreground %>
                        Format=<%= Format %>
                        AutoResize=<%= AutoResize %>
                        DistanceFromAxis=<%= DistanceFromAxis %>
                        Visible=<%= Visible %>
                        Italic=<%= Italic %>
                        FontFamily=<%= FontFamily %>
                        Bold=<%= Bold %>/>

            Return x
        End Function

        Public Sub InternalFromXElement(ByVal x As System.Xml.Linq.XElement)
            Dim cd = Function(s As String) Double.Parse(s, Globalization.CultureInfo.InvariantCulture)
            Dim cc = Function(s As String) If(String.IsNullOrEmpty(s), Nothing, (New Windows.Media.BrushConverter()).ConvertFromString(s))
            Dim ct = Function(s As String) (New Windows.ThicknessConverter()).ConvertFromInvariantString(s)

            Me.FontSize = cd(x.@FontSize)
            Me.Angle = cd(x.@Angle)
            Me.Foreground = cc(x.@Foreground)
            Me.Format = x.@Format
            Me.AutoResize = x.@AutoResize
            Me.DistanceFromAxis = cd(x.@DistanceFromAxis)
            Me.Visible = x.@Visible
            Me.FontFamily = x.@FontFamily
            Me.Italic = x.@Italic
            Me.Bold = x.@Bold
        End Sub

    End Class
End Namespace
